state 0.4.2

A library for safe and effortless global and thread-local state management.
Documentation

State   ci.svg crates.io docs.rs

A Rust library for safe and effortless global and thread-local state management.

extern crate state;

static GLOBAL: state::Storage<u32> = state::Storage::new();

GLOBAL.set(42);
assert_eq!(*GLOBAL.get(), 42);

This library can be used to easily implement:

  • Global Singletons
  • Global or Local Cached Values
  • Thread-Local Thunks
  • Dynamic Thread-Local Data
  • Typed Containers

See the documentation for more.

Usage

Include state in your Cargo.toml [dependencies]:

[dependencies]
state = "0.4"

Thread-local state management is not enabled by default. You can enable it via the tls feature:

[dependencies]
state = { version = "0.4", features = ["tls"] }

Testing

This library is extensively tested. Tests can be found in tests/main.rs. You can run the tests with cargo test --all-features.

License

State is licensed under either of the following, at your option: